import QtQuick
import QtQuick.Controls

Rectangle {
    color: "lightgray"

    Column {
        anchors.centerIn: parent
        spacing: 10

        Button {
            text: "加载有效组件"
            onClicked: loader.source = "component/ExistingComponent.qml"
        }

        Button {
            text: "加载无效组件"
            onClicked: loader.source = "component/NonExistentComponent.qml"
        }

        Loader {
            id: loader
            width: 200
            height: 150

            onStatusChanged: {
                if (status === Loader.Error) {
                    infoText.color = "red"
                } else {
                    infoText.color = "green"
                }
            }
        }

        Text {
            id: infoText
            color: "red"
            text: {
                switch(loader.status) {
                    case Loader.Null: return "组件未加载"
                    case Loader.Loading: return "正在加载..."
                    case Loader.Ready: return "加载完成"
                    case Loader.Error: return "加载错误, 无效组件"
                    default: return ""
                }
            }
            anchors.horizontalCenter: parent.horizontalCenter
        }
    }
}
